package com.example.shixunandjavagotoyangchen.BoosYang.Day002;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00102.SmileDay00102Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Contion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Model;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Presenter;
import com.example.shixunandjavagotoyangchen.R;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay002_1101 extends BasterFragment implements OnRefreshLoadMoreListener, NingserDay002_1101Contion.vier {

    public static SmartRefreshLayout Day00201SmartRefreshLayout;
    private RecyclerView Day00201RecyclerView;
    public boolean isning = true;
    public NingserDay002_1101Adpter adpter;
    public NingserDay002_1101Presenter presenter;

    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day002_1101;
    }

    @Override
    public void initView() {
        Day00201SmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.Day00201_SmartRefreshLayout);
        Day00201RecyclerView = (RecyclerView) findViewById(R.id.Day00201_RecyclerView);
        Day00201RecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL));
        Day00201SmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        presenter = new NingserDay002_1101Presenter(this,new NingserDay002_1101Model());
        presenter.ningtiong("Home_zidingyi.php");
    }

    @Override
    public void initDate() {

        Bitmap bitmap = BitmapFactory.decodeResource(null,R.mipmap.address_tag_);

    }

    @Override
    public void getvier(List<NingserDay002_1101Bean.ShujuBean> dataBeans) {
        Day00201SmartRefreshLayout.finishLoadMore();
        Day00201SmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new NingserDay002_1101Adpter(dataBeans);
            Day00201RecyclerView.setAdapter(adpter);
        }else {
            if (isning){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        isning =false;
        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

        if (isning){
            Log.i("aaa","la1");
        }
        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();

    }


    // TODO: Rename parameter arguments, choose names that match

}
